package com.zeedev.flyingsaucer.data;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

//import android.util.Log;

@Deprecated
public class Beer implements Serializable {
	
/*    [4196] => Array
    (
        [id] => 4196
        [brewer] => 662
        [style] => 87
        [country] => 1
        [description] => Bock beers are not always dark and Maibocks are blonde bock beers. "Mai" means May in German, and Maibocks are traditionally brewed for May 1st festivals that celebrate the end of winter. This beer has a very full and complex flavor that is best enjoyed slowly, allowing the different flavors time to develop on your tongue. You will find that it changes as you progress from the first taste to the lingering finish. The Malty sweetness is well balanced and blended with hop bitterness giving a full, rich blend of flavors.
        [container] => draught
        [name] => Free State Brinkley's Maibock
        [city] => Lawrence, KS
        [style_name] => Bock
        [country_name] => United States
        [brewer_name] => Free State Brewing Co
        [date_added] => 2010-05-19 00:02:52
        [comments] => 
        [rating] => 0
    )*/
	
	
	@Override
	public String toString() {
		//return "Beer: Name: "  + this.getName() + "; Style: " + this.getStyle_name();
		return this.getName();
	}
	
	
	
	public static final String TAG = "Beer";
	
//	@Override
//	public String toString() {
//		return "Beer [averageRating=" + averageRating + ", bottle=" + bottle
//				+ ", brewerId=" + brewerId + ", brewerName=" + brewerName
//				+ ", city=" + city + ", comments=" + comments + ", container="
//				+ container + ", countryId=" + countryId + ", countryName="
//				+ countryName + ", dateAdded=" + dateAdded + ", dbid=" + dbid
//				+ ", description=" + description + ", draught=" + draught
//				+ ", id=" + id + ", internalDateAdded=" + internalDateAdded
//				+ ", name=" + name + ", rating=" + rating + ", rawName="
//				+ rawName + ", simpleDate=" + simpleDate + ", styleId="
//				+ styleId + ", styleName=" + styleName + ", tasted=" + tasted
//				+ "]";
//	}

	Integer id;
	/**
	 * @param id
	 * @param brewerId
	 * @param styleId
	 * @param countryId
	 * @param container
	 * @param draught
	 * @param bottle
	 * @param rawName
	 * @param name
	 * @param description
	 * @param city
	 * @param styleName
	 * @param countryName
	 * @param brewerName
	 * @param comments
	 * @param rating
	 * @param averageRating
	 * @param dateAdded
	 * @param tasted
	 * @param simpleDate
	 * @param internalDateAdded
	 * @param dbid
	 */
	public Beer(Integer id, Integer brewerId, Integer styleId,
			Integer countryId, String container, Boolean draught,
			Boolean bottle, String rawName, String name, String description,
			String city, String styleName, String countryName,
			String brewerName, String comments, Integer rating,
			Integer averageRating, Date dateAdded, Boolean tasted,
			String simpleDate, Date internalDateAdded, Integer dbid) {
		super();
		this.id = id;
		this.brewerId = brewerId;
		this.styleId = styleId;
		this.countryId = countryId;
		this.container = container;
		this.draught = draught;
		this.bottle = bottle;
		//this.rawName = rawName;
		this.name = name;
		this.description = description;
		this.city = city;
		this.styleName = styleName;
		this.countryName = countryName;
		this.brewerName = brewerName;
		this.comments = comments;
		this.rating = rating;
		this.averageRating = averageRating;
		this.dateAdded = dateAdded;
		this.tasted = tasted;
		this.simpleDate = simpleDate;
		this.internalDateAdded = internalDateAdded;
		this.dbid = dbid;
	}



	Integer brewerId;
	Integer styleId;
	Integer countryId;
	
	String container;
	protected Boolean draught;
	protected Boolean bottle;
		
	//String rawName;
	String name;
	String nameSubscript;
	protected Boolean can;
	
	String description;
	String city;
	String styleName;
	String countryName;
	String brewerName;
	String comments;
	Integer rating;
	Integer averageRating;
	
	//String dateAddedRaw;
	Date dateAdded;
	Boolean tasted;
	protected String simpleDate = null;	
		
	protected Date internalDateAdded = null;
	Integer dbid;
	Integer memberId = null;
	
	//final
	public static final String dateFormat = "yyyy-MM-dd HH:mm:ss";
	public static final String dateFormatSimple = "MM-dd-yyyy";
	public static final SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
	public static final SimpleDateFormat sdf2 = new SimpleDateFormat(dateFormatSimple);

	
	
	public Date getInternalDateAdded() {
		return internalDateAdded;
	}

	public void setInternalDateAdded(Date internalDateAdded) {
		this.internalDateAdded = internalDateAdded;
	}
	
	public void setInternalDateAdded(Long internalDateAdded) {
		Date d = new Date();
		d.setTime(internalDateAdded);
		this.internalDateAdded = d;
	}

	public Integer getDbid() {
		return dbid;
	}

	public void setDbid(int dbid) {
		this.dbid = dbid;
	}

	public Beer() {
		super();

	}
	
	public Beer(String name, String styleName, Date dateAdded) {
		this();
		this.setRawName(name);
		this.styleName = styleName;
		this.setDateAdded(dateAdded);
	}
	
	public Beer(Integer id, Integer styleId, String rawName,
			String description, String styleName, Date dateAdded) {
		super();
		this.id = id;
		this.styleId = styleId;
		this.setRawName(rawName);
		this.description = description;
		this.styleName = styleName;
		this.setDateAdded(dateAdded);
	}

	public Integer getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Integer getBrewerId() {
		return brewerId;
	}

	public void setBrewerId(int brewerId) {
		this.brewerId = brewerId;
	}

	public Integer getStyleId() {
		return styleId;
	}

	public void setStyleId(int styleId) {
		this.styleId = styleId;
	}

	public Integer getCountryId() {
		return countryId;
	}

	public void setCountryId(int countryId) {
		this.countryId = countryId;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getContainer() {
		return container;
	}

	public void setContainer(String container) {
		this.container = container;
		this.bottle = container!=null?this.getContainer().equals("bottled") : false;
		this.draught = container!=null? this.getContainer().equals("draught") : false;
		//CAN IS SET BY RAW NAME
	}

	public String getName() {
		return name;
	}

	private void setName(String name) {
		this.name = name;
	}

//	public String getRawName() {
//		return rawName;
//	}

	public void setRawName(String rawName) {
		
		if (rawName != null && 
				( rawName.contains("(BTL)") || rawName.contains("(CAN)") )
			) {			
			this.name = rawName.substring(0,rawName.length()-6);
			this.nameSubscript = rawName.substring(rawName.length()-4,rawName.length()-1);
			this.can = rawName.contains("(CAN)");
		} else {
			this.name = rawName;
		}
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getStyleName() {
		return styleName;
	}

	public void setStyleName(String styleName) {
		this.styleName = styleName;
	}

	public String getCountryName() {
		return countryName;
	}

	public void setCountryName(String countryName) {
		this.countryName = countryName;
	}

	public String getBrewerName() {
		return brewerName;
	}

	public void setBrewerName(String brewerName) {
		this.brewerName = brewerName;
	}

//	public String getDateAddedRaw() {
//		return dateAddedRaw;
//	}
	
	protected String getSimpleDate() {
		return simpleDate;
	}
	
	protected void setSimpleDate(String in) {
		this.simpleDate = in;
	}
		
//	public void setDateAddedRaw(String dateAddedRaw) {
//	}

	public Date getDateAdded() {
		return dateAdded;
	}
	
	public String getDateAdded(Boolean simpleDateIn) {
		return simpleDateIn ? this.getSimpleDate() : this.getDateAdded().toString();		
	}

	public void setDateAdded(Date dateAdded) {
		this.dateAdded = dateAdded;
		if (dateAdded != null) {
			this.setSimpleDate(sdf2.format(this.getDateAdded()));
			this.setTasted(true);
		}
	}
	
	public void setDateAdded(String rawDateIn) {
		if (rawDateIn != null) {
			try {		
				this.setDateAdded(sdf.parse(rawDateIn));
				this.setSimpleDate(sdf2.format(this.getDateAdded()));
				this.setTasted(true);
			} catch (Exception e) {
				//Log.e(TAG, e.toString());
				e.printStackTrace();
			}
		}
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public Integer getRating() {
		return rating;
	}

	public void setRating(int rating) {
		this.rating = rating;
	}

	public Boolean getTasted() {
		return tasted!=null ? tasted : false;
	}

	private void setTasted(Boolean tasted) {
		this.tasted = tasted;
	}

	public Integer getAverageRating() {
		return averageRating;
	}

	public void setAverageRating(int averageRating) {
		this.averageRating = averageRating;
	}

	public Boolean isDraught() {
		return this.draught;
	}

	public Boolean isBottled() {
		return this.bottle;
	}

	public Boolean isCan() {
		return this.can;
	}

	
	public String getNameSubscript() {
		return nameSubscript;
	}

	public void setNameSubscript(String nameSubscript) {
		this.nameSubscript = nameSubscript;
	}

	public Integer getMemberId() {
		return memberId;
	}

	public void setMemberId(Integer memberId) {
		this.memberId = memberId;
	}
	
	
	

}
